import type { HttpError, HttpRequestConfig, HttpResponse, HttpTask } from '../../luch-request'
/**
 * @param {http} 请求实例
 */
export function logPlugin() {
  return {
    name: 'logPlugin',
    onRequestSuccess: (config: HttpRequestConfig<HttpTask>) => {
      console.log('%c请求发送成功', 'color:orange;font-weight:bold')
      console.log(config)
      console.log('%c请求发送成功-----end', 'color:orange;font-weight:bold')
      return config
    },
    onResponseSuccess: (response: HttpResponse<any, HttpTask>) => {
      console.log('%c响应成功', 'color:green;font-weight:bold')
      console.log(response)
      console.log('%c响应成功-----end', 'color:green;font-weight:bold')
      return response
    },
    onResponseFail: (err: HttpError<any, HttpTask>) => {
      console.log('%c响应失败', 'color:red;font-weight:bold')
      console.log(err)
      console.log('%c响应失败-----end', 'color:red;font-weight:bold')
      return Promise.reject(err)
    }
  }
}
